<?php

namespace Common\Model;

use Think\Model;

class FollowBbsModel extends Model
{
    protected $_auto = array(
        array('addtime', 'time', 1, 'function'),
    );

    /**
     * 检测是否关注过
     */
    public function chenk_follow_bbs($uid, $bid)
    {
        $map['uid'] = $uid;
        $map['bid'] = $bid;
        $item = $this->where($map)->find();
        return (bool)$item;
    }

    /**
     * 取消关注
     */
    public function clear_follow_bbs($uid, $bid)
    {
        $map['uid'] = $uid;
        $map['bid'] = $bid;
        return $this->where($map)->delete();
    }

    /**
     * 统计已关注用户数
     */
    public function get_follow_count($bid)
    {
        $map['bid'] = $bid;
        return $this->where($map)->count();
    }

    /**
     * 添加关注
     */
    public function follow_bbs($uid, $bid)
    {
        $data['uid'] = $uid;
        $data['bid'] = $bid;

        if ($this->create($data)) {
            return $this->add();
        } else {
            return false;
        }
    }
}